package com.hhd.pdf.context;

import com.itextpdf.text.Element;
import com.itextpdf.text.pdf.PdfWriter;
import com.hhd.pdf.GeneratorParameters;
import com.hhd.pdf.variable.VariableContext;
import com.hhd.pdf.variable.VariablePath;
import com.hhd.pdf.CommonUtils;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Builder
@Getter
@Setter
public class GeneratorContext {
    GeneratorParameters generatorParameters;
    List<Element> document;
    com.itextpdf.text.Document PDFdocument;
    PdfWriter pdfWriter;

    public GeneratorContext clone() {
        return GeneratorContext.builder()
                .generatorParameters(generatorParameters.clone())
                .document(document)
                .PDFdocument(PDFdocument)
                .build();
    }

    public VariableContext createRootVariableContext() {
        return VariableContext.builder()
                .basePath(VariablePath.root())
                .container(generatorParameters.getRenderData())
                .build();
    }

    public GeneratorContext init() {
        document = CommonUtils.newList();
        return this;
    }
}
